package edu.whu.rose.clock.kps.spindex;

import com.sleepycat.je.DatabaseEntry;
import com.sleepycat.je.DatabaseException;
import com.sleepycat.je.Environment;

import edu.whu.rose.clock.kps.datastruct.SimpleSubgraphVertex;
import edu.whu.rose.clock.ssql.binding.IntArrayBinding;
import edu.whu.rose.clock.ssql.binding.ShortestPathIndexItemBinding;
import edu.whu.rose.clock.ssql.binding.SubgraphVertexBinding;
import edu.whu.rose.clock.ssql.index.IndexDB;

public class ShortestPathIndexDB extends IndexDB {

	public ShortestPathIndexDB(Environment dbEnv, String dbName) {
		super(dbEnv, dbName);
	}
	
	public void put(int subgraph, int vertex, int[] arr) throws DatabaseException {
		DatabaseEntry key = new DatabaseEntry();
		DatabaseEntry value = new DatabaseEntry();
		
		SimpleSubgraphVertex ssv = new SimpleSubgraphVertex(subgraph, vertex);
		SubgraphVertexBinding svb = new SubgraphVertexBinding();
		svb.objectToEntry(ssv, key);
		
//		ShortestPathIndexItemBinding spiib = new ShortestPathIndexItemBinding();
//		spiib.objectToEntry(spii, value);
		
		IntArrayBinding iab = new IntArrayBinding();
		iab.objectToEntry(arr, value);
		
		put(key, value);
	}
	
	public int[] search(int subgraph, int vertex) throws DatabaseException {
		DatabaseEntry key = new DatabaseEntry();		
		SimpleSubgraphVertex ssv = new SimpleSubgraphVertex(subgraph, vertex);
		SubgraphVertexBinding svb = new SubgraphVertexBinding();
		svb.objectToEntry(ssv, key);
		
		DatabaseEntry value = get(key);
//		ShortestPathIndexItemBinding spiib = new ShortestPathIndexItemBinding();
		
		IntArrayBinding iab = new IntArrayBinding();
		return (int[]) iab.entryToObject(value);
	}

}
